package com.cxyzy.demo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.android.synthetic.main.activity_recycler_view.*
import java.util.*


class RecyclerViewActivity : AppCompatActivity() {
    private lateinit var adapter: RvAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler_view)
        initRecyclerView()
        loadData()
    }

    private fun initRecyclerView() {
        adapter = RvAdapter()
        recyclerView.adapter = adapter

        //设置布局类型
        recyclerView.layoutManager = GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false)
    }

    private fun loadData() {
        val data = ArrayList<String>()
        for (i in 0..50) {
            data.add("text-$i")
        }
        adapter.setData(data)
    }
}